<div class="FormNhapLieu">
	<div class="Title">
		<h3>
			Kết quả import danh sách học viên mới
		</h3>
	</div>
	<div>
		<ul>
			<?php
				if(isset($_POST['KhoaHoc']) && isset($_FILES['file']) && trim($_POST['KhoaHoc']) != "")
				{
					include_once '../classes/hocvien_bs.php';
					include_once '../classes/thuvienham.php';
					
					$filename = $_FILES["file"]["tmp_name"];
					$MaKhoaHoc = strtoupper(trim($_POST['KhoaHoc']));
					require_once '../import/excel_reader.php';
					$data = new Spreadsheet_Excel_Reader($filename,true,"UTF-8"); 
					
					$rowsnum = $data->rowcount($sheet_index=0); 
					$colsnum =  $data->colcount($sheet_index=0); 
					
					$Sus = 0;
					$Err = 0;
					
					for ($i = 2; $i < $rowsnum; $i++)
					{
						//echo "<br>".$data->val($i,1)." , ".$data->val($i,2);
						$HoTen = $data->val($i,2);
						$NgaySinh = ConvertDate($data->val($i,3));
						$GioiTinh = $data->val($i,4);
						$DienThoai = $data->val($i,5);
						$DiaChi = $data->val($i,6);
						$Email = $data->val($i,7);
						$MaChuongTrinh = $data->val($i,8);
						$MaThoiGian = $data->val($i,9);
						$Lop = $data->val($i,10);
						$HocPhiDuocGiam = $data->val($i,11);
						$MaTrangThai = 0;
						
						$HocVien = new hocvien_bs();
						$HocVien->SetMaHocVien(GetMaHocVien($MaKhoaHoc));
						$HocVien->SetMaLopHoc(NULL);
						$HocVien->SetMaChuongTrinh($MaChuongTrinh);
						$HocVien->SetMaThoiGianHoc($MaThoiGian);
						$HocVien->SetHoTen($HoTen);
						$HocVien->SetNgaySinh($NgaySinh);
						$HocVien->SetGioiTinh($GioiTinh);
						$HocVien->SetDiaChi($DiaChi);
						$HocVien->SetDienThoai($DienThoai);
						$HocVien->SetEmail($Email);
						$HocVien->SetLop($Lop);
						$HocVien->SetNgayDangKy(date("Y-m-d", time()));
						$HocVien->SetMaTrangThai($MaTrangThai);
						$HocVien->SetPIN(GeneratePIN());
						$HocVien->SetHocPhiDuocGiam($HocPhiDuocGiam);
						$HocVien->SetDaXoa(0);
						$HocVien->SetHocPhiDaNop(0);
						
						
						$RHocVien = $HocVien->Them();
						
						if($RHocVien)
							$Sus++;
						else
							$Err++;
					}
					$Total = $Sus + $Err;
					echo "<li>Tống số học viên có trong danh sách: $Total</li>";
					echo "<li>Thêm thành công: $Sus/$Total</li>";
				}
			?>
		</ul>
	</div>
</div>